home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / prodpack.zip / DB4PPSRC.EXE / _HELPSYS.PRG < prev    next >
Text File  |  1993-05-26  |  15KB  |  529 lines

  1. PROCEDURE _HelpSys
  2. PARAMETERS pc_file, pc_name, pc_dbf, pl_keep
  3. *---------------------------------------------------------------------------
  4. * NAME
  5. *   _HelpSys
  6. *
  7. * DESCRIPTION
  8. *   Help System for MFFUHELP programs as well as for the extended form
  9. *   capabilities.  Extended form help will be stored in a database called
  10. *   "Sys_Help".  MFFUHELP help will be stored in the dBASE Home directory
  11. *   in a database called "MFFUHELP".  Users may access the system by calling
  12. *   the procedure with their own help database name.  The structure of the
  13. *   database required is as follows:
  14. *
  15. *   Field  Field Name  Type       Width    Dec    Index
  16. *       1  HLP_FILE    Character     10               N
  17. *       2  HLP_TITLE   Character     25               N
  18. *       3  HLP_NAME    Character     10               N
  19. *       4  HLP_HEADNG  Character     40               N
  20. *       5  HLP_TEXT    Memo          10               N
  21. *       6  RELATED     Character      3               Y
  22. *
  23. *   In addition, three index tags need to exist:
  24. *
  25. *       INDEX ON UPPER( hlp_file - hlp_name ) TAG File_Name
  26. *       INDEX ON UPPER( hlp_file ) TAG Uniq_File UNIQUE
  27. *       INDEX ON related TAG related
  28. *
  29. * SYNOPSIS
  30. *   DO _HelpSys WITH pc_file, pc_name, pc_dbf, pl_keep
  31. *
  32. * PARAMETERS
  33. *   pc_file: Name of form file in the case of form help, and
  34. *            the of the popup in the case of system help
  35. *   pc_name: Name of the field in the case of form help, and
  36. *            the number of the bar in the case of system help
  37. *   pc_dbf:  Name of the database to be used by _HelpSys (MFFUHELP,
  38. *            Sys_Help, or an inputted name by the user)
  39. *   pl_keep: Keep help database open even if it wasn't open upon entry
  40. *
  41. *   Note: The the program is not sensative to the case (upper or lower)
  42. *         of the parameters, nor the spacing between pc_file and pc_name
  43. *
  44. * EXAMPLE
  45. *   DO _HelpSys WITH "Client", "Address", "Sys_Help", .T.
  46. *      ** OR **
  47. *   DO _HelpSys WITH "MakeLook", "3", "MFFUHELP", .F.
  48. *
  49. *---------------------------------------------------------------------------
  50.  
  51.   PRIVATE gc_file, gc_elev, gc_file, gc_name, gc_shaft, gn_menwith, gn_top, ;
  52.           lc_dbf, lc_dbfname, lc_hlp_aka, lc_msg_col, lc_border, ;
  53.           lc_sav_col, lc_title, lc_view, ll_cancel, ll_cat, ll_close, ;
  54.           ll_content, ll_curs, ll_exct, ll_flds, ll_near, ll_stats, ll_tlk, ;
  55.           ln_memo_w, ln_recno, lc_headng
  56.  
  57.   PRIVATE gnLevel                       && Three values: EDIT:1,MOD:2,TOP:3
  58.   gnLevel = 1
  59.   PRIVATE gnMemo                        && Current line in help frame
  60.   gnMemo = 1
  61.   PRIVATE ef_ms01_0,ef_ms02_0,ef_ms03_0,ef_ms04_0,ef_ms05_0,;
  62.           ef_ms06_0,ef_ms07_0,ef_ms08_0,ef_ms09_0
  63.   STORE "" TO ef_ms01_0,ef_ms02_0,ef_ms03_0,ef_ms04_0,ef_ms05_0,;
  64.               ef_ms06_0,ef_ms07_0,ef_ms08_0,ef_ms09_0
  65.   PRIVATE ef_scr1_0,ef_scr2_0,ef_scr3_0,ef_scr4_0,ef_scr5_0,;
  66.           ef_scr6_0,ef_scr7_0,ef_scr8_0,ef_scr9_0
  67.   PRIVATE ti_text
  68.   ti_text = ""
  69.   PRIVATE nMemoLines
  70.   nMemoLines = 0
  71.   PRIVATE cPopDef
  72.   cPopDef = ""
  73.   PRIVATE gnBarSel
  74.   gnBarSel = -1
  75.  
  76.   *------------------------------------------------------------
  77.   *-- Prevent calling the help system, while in the help system
  78.   *------------------------------------------------------------
  79.   IF TYPE( "pc_file" ) = "C" .AND. UPPER( pc_file ) $ 'DLGCONT,DLGEDIT,DLGHELP'
  80.     RETURN
  81.   ENDIF
  82.  
  83.   ON KEY LABEL F1
  84.   ll_tlk = _TalkMode( .F. )        && Save Environment ...
  85.   PRIVATE lTrap, lEscape
  86.   lTrap = SET( "TRAP" ) = "ON"
  87.   SET TRAP OFF
  88.   lEscape = SET( "ESCAPE" ) = "ON"
  89.   SET ESCAPE OFF
  90.  
  91.  
  92.   *------------------------------------------------------------------
  93.   *-- Save the database environment, and shut down any view if active
  94.   *------------------------------------------------------------------
  95.   IF ISBLANK( SET( "VIEW" ) )
  96.     lc_hlp_aka = ALIAS()
  97.     lc_view = ""
  98.   ELSE
  99.     lc_view = SET( "VIEW" )
  100.     ln_recno = RECNO()
  101.     CLOSE DATABASES
  102.   ENDIF
  103.  
  104.   ln_memo_w = SET( "MEMOWIDTH" )
  105.  
  106.   ll_cat = SET( "CATALOG" ) = "ON"
  107.   ll_exct = SET( "EXACT" ) = "OFF"
  108.   ll_near = SET( "NEAR" ) = "OFF"
  109.   ll_flds = SET( "FIELDS" ) = "ON"
  110.   ll_stats = SET( "STATUS" ) = "ON"
  111.  
  112.   *-----------------------
  113.   *-- Setup the scroll bar
  114.   *-----------------------
  115.   gc_shaft = CHR( 176 )            && Set Elevator characters
  116.   gc_elev = "-"
  117.   STORE gc_shaft TO ef_scr1_0, ef_scr2_0, ef_scr3_0, ef_scr4_0, ef_scr5_0, ;
  118.                     ef_scr6_0, ef_scr7_0, ef_scr8_0, ef_scr9_0
  119.  
  120.  
  121.   *------------------------------------------------------------------
  122.   *-- If status is on set it off to prevent status bar updates during
  123.   *-- execution, and restore screen to hide that fact from user
  124.   *------------------------------------------------------------------
  125.   IF ll_stats
  126.     SAVE SCREEN TO _HelpSys
  127.     SET STATUS OFF
  128.     RESTORE SCREEN FROM _HelpSys
  129.  
  130.     *-- If clock is active, refresh it
  131.     IF SET( "CLOCK" ) = "ON"
  132.       SET CLOCK ON
  133.     ENDIF
  134.   ENDIF
  135.  
  136.   SET MEMOWIDTH TO 65
  137.   SET CATALOG OFF
  138.   SET EXACT ON
  139.   SET NEAR ON
  140.   SET FIELDS OFF
  141.  
  142.   IF TYPE( "FXl_dev" ) = "U"
  143.     FXl_dev = .F.
  144.   ENDIF
  145.  
  146.   IF TYPE( "pc_dbf" ) = "L" .OR. ;
  147.      ( TYPE( "pc_dbf" ) = "C" .AND. ISBLANK( pc_dbf ) )
  148.     pc_dbf = "MFFUHELP"
  149.   ENDIF
  150.  
  151.   STORE .F. TO ll_content, ll_close
  152.  
  153.   *--------------------------------------------------------------------
  154.   *-- If no parameters are sent, dBASE will set their values to be
  155.   *-- logical "False" which will cause data type mismatches in the
  156.   *-- program.  Therefore if the user has failed to send any or all the
  157.   *-- parameters, initialize them to be defaults
  158.   *--------------------------------------------------------------------
  159.   DO CASE
  160.     CASE TYPE( "pc_file" ) = "L"
  161.       STORE "" TO pc_file, pc_name
  162.     CASE TYPE( "pc_name" ) = "L"
  163.       pc_name = ""
  164.   ENDCASE
  165.   lc_dbf = UPPER( TRIM( pc_dbf ) )
  166.   gc_file = UPPER( TRIM( pc_file ) )
  167.   gc_name = UPPER( TRIM( pc_name ) )
  168.  
  169.   lc_dbfname = IIF( lc_dbf = "MFFUHELP", ;
  170.                     HOME() + "MFFUHELP", ;
  171.                     lc_dbf ;
  172.                   )
  173.  
  174.   *------------------------------------
  175.   *-- If all necessary help files exist
  176.   *------------------------------------
  177.   ll_cancel = .F.
  178.   IF FILE( lc_dbfname + ".dbf" ) .AND. FILE( lc_dbfname + ".mdx" ) .AND. ;
  179.      FILE( lc_dbfname + ".dbt" )
  180.  
  181.     DO _HeOpenDb
  182.  
  183.   ELSE
  184.     *-------------------------------------------
  185.     *-- Try the home directory for the help file
  186.     *-------------------------------------------
  187.     lc_dbfname = HOME() + lc_dbfname
  188.     IF FILE( lc_dbfname + ".dbf" ) .AND. FILE( lc_dbfname + ".mdx" ) .AND. ;
  189.        FILE( lc_dbfname + ".dbt" )
  190.  
  191.       DO _HeOpenDb
  192.  
  193.  
  194.     ELSE                    && Not all necessary files exist
  195.  
  196.       DO _He_NoFil WITH lc_dbfname    && Display appropriate error message
  197.       ll_cancel = .T.            && Set don't do flag
  198.  
  199.     ENDIF
  200.  
  201.   ENDIF
  202.  
  203.   IF .NOT. ll_cancel
  204.     *-------------------------------------------------------------------
  205.     *-- Position help database to desired help points, if no help points
  206.     *-- were given, or the help points were erroneous, activate popups
  207.     *-- which will allow the user to select the help he wants.
  208.     *-- _HelpMain is a contents of contents, _HelpHdr is a contents
  209.     *-- of topics from the same form or popup
  210.     *-------------------------------------------------------------------
  211.     IF .NOT. ISBLANK( gc_file )
  212.  
  213.       IF .NOT. ISBLANK( gc_name )
  214.         SEEK gc_file + gc_name
  215.  
  216.         DO CASE
  217.  
  218.           *-- Case it doesn't exist but develop mode is on
  219.           CASE FXl_dev .AND. .NOT. FOUND()
  220.  
  221.             *-- Create default title
  222.             lc_headng = [Help for: ] + _Proper( _StrTran( gc_file, "_", " " ) )
  223.             lc_title = [Help for: ] + _Proper( _StrTran( gc_name, "_", " " ) )
  224.             *-- Create new help record
  225.             APPEND BLANK
  226.             *-- replace fields with parameters
  227.             REPLACE hlp_file WITH gc_file, hlp_name WITH gc_name, ;
  228.                     hlp_headng WITH lc_title, hlp_title WITH lc_headng
  229.             gnLevel = 1
  230.  
  231.           *-- Case it doesn't exist and develop mode is off
  232.           CASE  .NOT. FXl_dev .AND. .NOT. FOUND()
  233.             SEEK gc_file
  234.  
  235.             IF TRIM( hlp_file ) <> gc_file  && file doesn't exist
  236.  
  237.               *-- Sys_help cannot go to main table of contents
  238.               IF lc_dbf <> "SYS_HELP"
  239.                 STORE "" TO gc_file, gc_name
  240.                 gnLevel = 3
  241.  
  242.               ELSE
  243.                 DO _Err_Box WITH [No help for form file: ] + gc_file
  244.                 ll_cancel = .T.
  245.               ENDIF
  246.  
  247.             ELSE
  248.               gc_name = ""
  249.               gnLevel = 2
  250.             ENDIF
  251.  
  252.           OTHERWISE
  253.             gnLevel = 1
  254.  
  255.         ENDCASE
  256.  
  257.       ELSE                && gc_name was blank
  258.         SEEK gc_file
  259.  
  260.         IF TRIM( hlp_file ) = gc_file    && file doesn't exist
  261.           gnLevel = 2
  262.         ELSE                && gc_file was erroneous
  263.  
  264.           IF lc_dbf <> "SYS_HELP"
  265.             gc_file = ""
  266.             gnLevel = 3
  267.           ELSE
  268.             DO _Err_Box WITH [No help for form file: ] + gc_file
  269.             ll_cancel = .T.
  270.           ENDIF
  271.  
  272.         ENDIF
  273.  
  274.       ENDIF                && .NOT. ISBLANK( gc_name )
  275.  
  276.     ELSE                && gc_file was blank
  277.  
  278.       IF lc_dbf <> "SYS_HELP"
  279.         gnLevel = 3
  280.  
  281.       ELSE
  282.         DO _Err_Box WITH [No help for form file: ] + gc_file
  283.         ll_cancel = .T.
  284.       ENDIF
  285.  
  286.     ENDIF                && .NOT. ISBLANK( gc_file )
  287.  
  288.     *---------------------------------
  289.     *-- Setup the dialog box variables
  290.     *---------------------------------
  291.     FXL_Cancel = .F.
  292.     FXL_NoChng = .F.
  293.     DECLARE DLGCONT[ 5 ]
  294.       DLGCONT[ 1 ]     = 0
  295.       DLGCONT[ 2 ]     = .F.
  296.       DLGCONT[ 3 ]     = .F.
  297.       DLGCONT[ 4 ]     = .T.
  298.       DLGCONT[ 5 ]     = .F.
  299.  
  300.     DECLARE DLGEDIT[ 5 ]
  301.       DLGEDIT[ 1 ]     = SPACE( 25 )
  302.       DLGEDIT[ 2 ]     = SPACE( 40 )
  303.       DLGEDIT[ 3 ]     = .F.
  304.       DLGEDIT[ 4 ]     = .T.
  305.       DLGEDIT[ 5 ]     = .F.
  306.  
  307.     DECLARE DLGHELP[ 6 ]
  308.       DLGHELP[ 1 ]     = .F.
  309.       DLGHELP[ 2 ]     = .F.
  310.       DLGHELP[ 3 ]     = .F.
  311.       DLGHELP[ 4 ]     = .F.
  312.       DLGHELP[ 5 ]     = .F.
  313.       DLGHELP[ 6 ]     = .F.
  314.     *------------------------------------------------------
  315.     *-- Loop between the help dialog boxes until FXL_Cancel
  316.     *------------------------------------------------------
  317.     DO WHILE .NOT. FXL_Cancel
  318.       DO CASE
  319.         CASE gnLevel = 1
  320.           gc_file = TRIM( hlp_file )
  321.           gc_name = hlp_name
  322.           ti_text = Hlp_Headng
  323.           gnMemo = 1
  324.           DO DlgSetHp
  325.           DO DlgHelp
  326.         CASE gnLevel = 2
  327.           gc_file = TRIM( hlp_file )
  328.           gc_name = ""
  329.           gnMemo = 1
  330.           gnBarSel = -1
  331.           DLGCONT[ 1 ] = 0
  332.           TI_TEXT = Hlp_Title
  333.           FXL_CANCEL = .F.
  334.           DO DlgCont
  335.           IF .NOT. FXL_CANCEL
  336.             IF gnBarSel > 0
  337.               GO TOP
  338.               SKIP gnBarSel - 1
  339.               SET KEY TO
  340.               gnMemo = 1
  341.               DO DlgSetHp
  342.               TI_TEXT = TRIM( hlp_headng )
  343.               gnLevel = 1
  344.             ENDIF
  345.           ENDIF
  346.         CASE gnLevel = 3
  347.           TI_TEXT = [Table of Contents]
  348.           gnMemo = 1
  349.           gnBarSel = -1
  350.           DLGCONT[ 1 ] = 0
  351.           gnMemo = 1
  352.           DO DlgCont
  353.           FXL_CANCEL = .F.
  354.           IF .NOT. FXL_CANCEL
  355.             IF gnBarSel > 0
  356.               GO TOP
  357.               SKIP gnBarSel - 1
  358.               SET ORDER TO File_Name
  359.               gnLevel = 2
  360.             ENDIF
  361.           ENDIF
  362.       ENDCASE
  363.     ENDDO
  364.  
  365.   ENDIF                    && .NOT. ll_cancel
  366.  
  367.   *----------------------
  368.   *-- Restore Environment
  369.   *----------------------
  370.   IF ll_close
  371.     USE
  372.   ENDIF
  373.  
  374.   IF .NOT. ISBLANK( lc_view )
  375.     SET VIEW TO ( lc_view )
  376.     GO ln_recno
  377.   ELSE
  378.  
  379.     IF .NOT. ISBLANK( lc_hlp_aka )
  380.       SELECT ( lc_hlp_aka )
  381.     ENDIF
  382.  
  383.   ENDIF
  384.  
  385.   IF ll_cat
  386.     SET CATALOG ON
  387.   ENDIF
  388.  
  389.   IF ll_exct
  390.     SET EXACT OFF
  391.   ENDIF
  392.  
  393.   IF ll_near
  394.     SET NEAR OFF
  395.   ENDIF
  396.  
  397.   IF ll_flds
  398.     SET FIELDS ON
  399.   ENDIF
  400.  
  401.   IF ll_stats
  402.     SET STATUS ON
  403.     RESTORE SCREEN FROM _HelpSys
  404.     RELEASE SCREEN _HelpSys
  405.  
  406.     *-- If clock is active, refresh it
  407.     IF SET( "CLOCK" ) = "ON"
  408.       SET CLOCK ON
  409.     ENDIF
  410.  
  411.   ENDIF
  412.  
  413.   SET MEMOWIDTH TO ln_memo_w
  414.  
  415.   IF lTrap
  416.     SET TRAP ON
  417.   ELSE
  418.     SET TRAP OFF
  419.   ENDIF
  420.   IF lEscape
  421.     SET ESCAPE ON
  422.   ELSE
  423.     SET ESCAPE OFF
  424.   ENDIF
  425.  
  426.  
  427.   IF _TalkMode( ll_tlk)
  428.   ENDIF
  429.  
  430.   IF TYPE( "gc_hsave" ) = "C"
  431.     ON KEY LABEL F1 DO _HelpSys WITH &gc_hsave
  432.   ENDIF
  433.  
  434. RETURN
  435. *-- EOP: _HelpSys WITH pc_file, gc_name, pc_dbf
  436.  
  437.  
  438. PROCEDURE _HeOpenDb
  439. *----------------------------------------------------------------------------
  440. * NAME
  441. *   _HeOpenDb - Opens the help file using lc_DbfName
  442. *
  443. *----------------------------------------------------------------------------
  444.   *-- Open or select help file
  445.   IF SELECT( lc_dbf ) > 0
  446.     SELECT ( lc_dbf )
  447.   ELSE
  448.  
  449.     DO _SetOnEr
  450.     SELECT SELECT()
  451.     USE ( lc_dbfname )
  452.     ON ERROR
  453.  
  454.     IF .NOT. pl_keep            && If not keep help file open flag
  455.       ll_close = .T.            && set close flag
  456.     ENDIF
  457.  
  458.   ENDIF
  459.  
  460.   *-- If all necessary index tags exist
  461.   IF TYPE( "FXL_Error" ) <> "L" .AND. ;
  462.      TAGNO( "File_Name" ) > 0 .AND. TAGNO( "Uniq_File" ) > 0
  463.  
  464.     SET ORDER TO File_Name        && Set needed tag
  465.     ll_cancel = .F.            && Clear don't do flag
  466.   ELSE                && Tag or tags don't exist
  467.  
  468.     IF TYPE( "FXL_Error" ) <> "L"
  469.       DO _Err_Box WITH [Help index file missing tags: ] + ;
  470.                        TRIM( lc_dbf ) + ".MDX"
  471.     ELSE
  472.       RELEASE FXL_Error
  473.     ENDIF
  474.  
  475.     ll_cancel = .T.            && Set don't do flag
  476.   ENDIF
  477.  
  478. RETURN
  479. *-- EOP: _HeOpenDb
  480. PROCEDURE _He_NoFil
  481. PARAMETER pc_dbfname
  482. *---------------------------------------------------------------------------
  483. * NAME
  484. *   _He_NoFil
  485. *
  486. * DESCRIPTION
  487. *   Displays appropriate error message depending on which help data files
  488. *   (.dbf, .dbt, or .mdx) are missing
  489. *
  490. * SYNOPSIS
  491. *   DO _He_NoFil WITH pc_dbfname
  492. *
  493. * PARAMETERS
  494. *   pc_dbfname: Name of help database to check
  495. *
  496. * EXAMPLE
  497. *   DO _He_NoFil WITH lc_dbfname
  498. *   ll_cancel = .T.
  499. *
  500. * LIMITATIONS
  501. *   None
  502. *
  503. * DEPENDENCIES
  504. *   Called By: _HelpSys
  505. *   Calls:     Nothing
  506. *
  507. *---------------------------------------------------------------------------
  508.  
  509.   DO CASE
  510.     *-- If database doesn't exist
  511.     CASE .NOT. FILE( pc_dbfname + ".dbf" )
  512.       DO _Err_Box WITH [File not found: ] + pc_dbfname + ".DBF"
  513.     *-- If memo file doesn't exist
  514.     CASE .NOT. FILE( pc_dbfname + ".dbt" )
  515.       DO _Err_Box WITH [File not found: ] + pc_dbfname + ".DBT"
  516.     *-- If production MDX file doesn't exist
  517.     OTHERWISE
  518.       DO _Err_Box WITH [File not found: ] + pc_dbfname + ".MDX"
  519.  
  520.   ENDCASE
  521.  
  522. RETURN
  523. *-- EOP: _He_NoFil WITH pc_dbfname
  524. *'---------------------------------------------------------------------
  525. *' $Log: $
  526. *'---------------------------------------------------------------------
  527.  
  528.  
  529.